import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);

// 双击路由重复
const originpush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originpush.call(this, location).catch(err => err)
}
// 路由懒加载
const Home = () => import("../views/home/Home.vue");
const Category = () => import("../views/category/Category.vue");
const ShopCart = () => import("../views/shopcart/ShopCart.vue");
const Profile = () => import("../views/profile/Profile.vue");
const detail = () => import('../views/detail/Detail')
const routes = [
  {
    path: "/",
    redirect: "/home",
  },
  {
    path: "/home",
    component: Home,
  },
  {
    path: "/category",
    component: Category,
  },
  {path: "/shopcart", component: ShopCart},
  {path: "/profile", component: Profile},
  {path: "/detail/:goodsId", component: detail},
];
const router = new VueRouter({
  routes,
  mode: "history"
});

export default router;
